package com.prp.db;

import org.hibernate.Transaction;

import com.prp.db.daoimpl.mysql.NeighbourRelationshipDAO;
import com.prp.db.idao.INeighbourRelationshipDAO;
import com.prp.db.idao.IUserInformationDAO;
import com.prp.db.po.NeighbourRelationship;
import com.prp.db.po.UserInformation;

public class Example {
	public static void main(String args[]){
		DAOFactory factory = DAOFactory.getDAOFactory();
		INeighbourRelationshipDAO nrDAO = factory.getNeighbourRelationshipDAO();
		NeighbourRelationship nr = new NeighbourRelationship();
		IUserInformationDAO userDAO = factory.getUserInformationDAO();
		Transaction tx = null;
		try {
			tx = HibernateSessionFactory.getSession().beginTransaction();
			UserInformation user1 = (UserInformation)userDAO.findByProperty("email", "1").get(0);
			if(user1 == null)
				return;
			UserInformation user2 = userDAO.findById(2);
			if(user2 == null)
				return;
//			nr.setFromId(user1.getUserId());
//			nr.setToId(user2.getUserId());
			nr.setBuildup(true);
			nrDAO.save(nr);
			tx.commit();
		} catch (Exception e) {
			if(tx!=null)
				tx.rollback();
			e.printStackTrace();
		}
	}
}
